<script>
var productlist={};
var showdataprice=0;
var orderid=0;
var userid=0;
var userlist={};
var creditcount=1;
var producttemp=0;
var enablekeyborad=0;
var opencalulator=0;
var alldata=0;
var alldata2=0;
var tempurserid=0;
var tempidcreditnow=0;
var readyanswer=0;

function calculateorder(productid,img,title,price,discount,suborderid,note)
{
var code='';
if($('.wrpSaleLst .wrpInnSaleLst').length==0)
{
code+='<div class="wrpInnSaleLst">';

}
if(productid)
{

if(productlist[productid])
{
productlist[productid]['count']=productlist[productid]['count']+1;

$('#checkproductdata-'+productid+' .amtItm.clTxtPOSB.fs09').html(productlist[productid]['count']);

var priceset=productlist[productid]['price'];
var showminus='';
if(productlist[productid]['discount'])
{
priceset=productlist[productid]['discount'];
showminus='-';
}


$('#checkproductdata-'+productid+' .clTxtPOSB.fs02').html(showminus+(productlist[productid]['count']*priceset)+' Baht');

}else
{



productlist[productid]={count:1,title:title,img:img,productid:productid,price:price,discount:discount,suborderid:suborderid,credit:0,note:''};


showdataprice=price;

if(discount)
{
showdataprice='-'+discount;
}


code += '<div onclick="popitemproduct('+productid+')" id="checkproductdata-'+productid+'" class="saleLst pdPmtLst clBd2 bdBtm clearfix">\n';
code += '<div class="amtLst">\n';
code += '<div class="amtInLst">\n';
code += '<span class="amtItm clTxtPOSB fs09">1</span>\n';
//code += '<span class="stateItm state1"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="imgLst">\n';
code += '<img src="'+img+'" alt="">\n';
code += '</div>\n';
code += '<div class="ttlLst">\n';
code += '<span class="clTxtPOSB fs03">'+title+'</span>\n';
code += '</div>\n';
code += '<div class="prcLst">\n';
code += '<span class="clTxtPOSB fs02">'+showdataprice+' Baht</span>\n';
code += '</div>\n';
code += '</div>';


}


}
else
{

if(tempidcreditnow)
{
productlist['credit-'+tempidcreditnow]={count:1,title:title,img:img,productid:productid,price:price,discount:discount,suborderid:suborderid,credit:0,note:note};
$('#creditcheck-'+tempidcreditnow+' .ttlLst .clTxtPOSB').html(title);


var showdata=price;



if(discount)
{
showdata='-'+discount;

}

$('#creditcheck-'+tempidcreditnow+' .prcLst .clTxtPOSB').html(showdata+' Baht');
calorder();
return false;


}else
{
productlist['credit-'+creditcount]={count:1,title:title,img:img,productid:productid,price:price,discount:discount,suborderid:suborderid,credit:0,note:note};
code += '<div onclick="editcreditdata('+creditcount+')" id="creditcheck-'+creditcount+'" class="saleLst spcLst clBd2 bdBtm clearfix">\n';
code += '<div class="amtLst">\n';
code += '<div class="amtInLst">\n';
code += '<span class="amtItm clTxtPOSB fs09">1</span>\n';
code += '</div>\n';
var showdata=price;



if(discount)
{
showdata='-'+discount;

}



code += '</div>\n';
code += '<div class="imgLst">\n';
code += '<div class="wrpSpcLst">\n';
code += '<span class="icoPOS icoSpc"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="ttlLst">\n';
code += '<span class="clTxtPOSB fs03">'+title+'</span>\n';
code += '</div>\n';
code += '<div class="prcLst">\n';
code += '<span class="clTxtPOSB fs02">'+showdata+' Baht</span>\n';
code += '</div>\n';
code += '</div>';
creditcount++;
}
}


if($('.wrpSaleLst .wrpInnSaleLst').length==0)
{
code+='</div">';
$('.wrpSaleLst').html(code);

}else
{

$('.wrpSaleLst .wrpInnSaleLst').append(code);

}

calorder();


}
function popitemproduct(productid)
{
producttemp=productid;

$('.wrprPopPOS.wrprPopSaleLst .imgItmPopSaleLst img').attr('src',productlist[productid]['img']);
$('.wrprPopPOS.wrprPopSaleLst .ttlItmPopSaleLst .clTxtPOSB.fs09').html(productlist[productid]['title']);



var priceset=productlist[productid]['price'];
if(productlist[productid]['discount'])
{
priceset='-'+productlist[productid]['discount'];

}

$('.wrprPopPOS.wrprPopSaleLst .ttlItmPopSaleLst .clTxtPOSB.fs05').html(priceset+' Baht');
$('.wrprPopPOS.wrprPopSaleLst textarea').val(productlist[productid]['note']);


$('.wrprPopPOS.wrprPopSaleLst .wrpQttPopSaleLst .qttSale .clTxtPOSB.fs11').html(productlist[productid]['count']);

$('.wrprPopPOS.wrprPopSaleLst').fadeIn();

}
function savetempproduct()
{

productlist[producttemp]['note']=$('.wrprPopPOS.wrprPopSaleLst textarea').val();

productlist[producttemp]['count']=parseInt($('.wrprPopPOS.wrprPopSaleLst .wrpQttPopSaleLst .qttSale .clTxtPOSB.fs11').html(),10);







$('#checkproductdata-'+producttemp+' .amtItm.clTxtPOSB.fs09').html(productlist[producttemp]['count']);

var priceset=productlist[producttemp]['price'];
var showminus='';
if(productlist[producttemp]['discount'])
{
priceset=productlist[producttemp]['discount'];
showminus='-';
}


$('#checkproductdata-'+producttemp+' .clTxtPOSB.fs02').html(showminus+(productlist[producttemp]['count']*priceset)+' Baht');

calorder();
$('.wrprPopPOS.wrprPopSaleLst').fadeOut();



}
function increproduct()
{
var qproduct=$('.wrprPopPOS.wrprPopSaleLst .wrpQttPopSaleLst .qttSale .clTxtPOSB.fs11').html();

var nq=parseInt(qproduct,10)+1;


$('.wrprPopPOS.wrprPopSaleLst .wrpQttPopSaleLst .qttSale .clTxtPOSB.fs11').html(nq);



}
function decreproduct()
{
var qproduct=$('.wrprPopPOS.wrprPopSaleLst .wrpQttPopSaleLst .qttSale .clTxtPOSB.fs11').html();

if(parseInt(qproduct,10)!=1)
{
var nq=parseInt(qproduct,10)-1;
$('.wrprPopPOS.wrprPopSaleLst .wrpQttPopSaleLst .qttSale .clTxtPOSB.fs11').html(nq);
}







}
function opencalcutator()
{
opencalulator=1;
enablekeyborad=1;
$('.wrpPOS').addClass('l337');

}
function closecalcutator()
{
if(opencalulator==1)
{
opencalulator=0;
enablekeyborad=0;
$('.wrpPOS').removeClass('l337');
var lasttext=$('input.tenderInp').val();
if(lasttext!='')
{
var testdata= lasttext.slice(-1);
if(!$.isNumeric(testdata))
{
$('input.tenderInp').val('');


}else
{
var numberdata= eval(lasttext);

$('input.tenderInp').val(numberdata);
calorder();

}
}
$('.wrpOutPopSpc').removeClass('l170p');

}

}
function removetempproduct()
{
delete productlist[producttemp];
$('#checkproductdata-'+producttemp).remove();
calorder();
$('.wrprPopPOS.wrprPopSaleLst').fadeOut();

}
function calorder()
{

alldata=0;
$.each( productlist, function( key, value ) {

if(value.price)
{
alldata=alldata+(value.count*value.price);


}else if(value.discount)
{
alldata=alldata-(value.count*value.discount);


}


})

$('.wrpSaleCart .spnSalePrc.clTxtPOSB.fs11').html(alldata+' Baht');

var lastdata=$('input.tenderInp').val();
if(lastdata!=''&&alldata!=0)
{


lastdata=parseInt(lastdata,10);



$(".changeCost.clTxt3.fs11").html(lastdata-alldata);

}





}
function settexttoinput(text)
{


var lasttext=$(laststringinput).val();
if(lasttext=='')
{
if(text=='0'||text=='00')
{

return true;
}


}


var testdata= lasttext.slice(-1);

if(text=='00')
{


if($.isNumeric(testdata)||text=='.')
{
    

}else
{

return true;
}



}



if(!$.isNumeric(testdata)&&!$.isNumeric(text))
{
return true;


}




$(laststringinput).val(lasttext+text);


}
function changesignstatus(status)
{
$('.wrprPopPOS.wrprPopSpc .btnPOSC.btnSpcSign.fs05').removeClass('spcSignTg');
if(status==1)
{
$('.wrprPopPOS.wrprPopSpc .increpossign').addClass('spcSignTg');

}else
{
$('.wrprPopPOS.wrprPopSpc .minuspossign').addClass('spcSignTg');

}



}
function savecreditdataall()
{

var img='';

var title=$('input[name="namecredit"]').val();
var discount=$('input[name="numcredit"]').val();
var price=$('input[name="pricecredit"]').val();
var note=$('textarea[name="notecredit"]').val();


if($('.wrprPopPOS.wrprPopSpc .specialbtn').hasClass('spcTg'))
{
if($('.wrprPopPOS.wrprPopSpc .increpossign').hasClass('spcSignTg'))
{
discount=0;
}else
{
discount=price;
price=0;
}



calculateorder(0,img,title,price,discount,0,note);

}else
{
calculateorder(0,img,title,price,discount,0,note);

}



$('.wrprPopSpc').fadeOut("fast");




}
function editcreditdata(creditidnow)
{
tempidcreditnow=creditidnow;
var datarow=productlist['credit-'+creditidnow];

$('input[name="namecredit"]').val(datarow.title);
$('input[name="numcredit"]').val(datarow.credit);

$('.minuspossign').removeClass('spcSignTg');
$('.increpossign').removeClass('spcSignTg');

if(datarow.discount)
{
$('input[name="pricecredit"]').val(datarow.discount);
$('.minuspossign').addClass('spcSignTg');

}else
{
$('input[name="pricecredit"]').val(datarow.price);
$('.increpossign').addClass('spcSignTg');
}

$('textarea[name="notecredit"]').val(datarow.note);
$('.wrprPopPOS.wrprPopSpc').fadeIn();
$('.wrprPopSpc .wrpInBtnBdSaleLst').show();

}
function removethisspecial()
{
delete productlist['credit-'+tempidcreditnow];
$('#creditcheck-'+tempidcreditnow).remove();
$('.wrprPopPOS.wrprPopSpc').fadeOut();

}
function calallchange()
{

var lasttext=$(laststringinput).val();

var testdata= lasttext.slice(-1);
if(laststringinput!="input.tenderInp")
{
if(!$.isNumeric(testdata))
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Can not calculate order');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}

var numberdata= eval(lasttext);
$(laststringinput).val(numberdata);
opencalulator=0;
enablekeyborad=0;
$('.wrpPOS').removeClass('l337');
$('.wrpOutPopSpc').removeClass('l170p');
return false;
}


if(alldata==0)
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Choose Order');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;

}


if(lasttext)
{
if(!$.isNumeric(testdata))
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Can not calculate order');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}else
{

var numberdata= eval(lasttext);

if(numberdata<alldata)
{

$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Cash must be greater than or equal to the total price.');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;

}else
{
$(laststringinput).val(numberdata);
opencalulator=0;
enablekeyborad=0;
$('.wrpPOS').removeClass('l337');



$(".changeCost.clTxt3.fs11").html(numberdata-alldata);

}



}
}else
{

$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Input Number');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;

}


}
function deletetexttoinput()
{

var lasttext=$(laststringinput).val();
lasttext=lasttext.substr(0,lasttext.length - 1);

$(laststringinput).val(lasttext);
}
function checkuseraddmember()
{

if($('#membercheck').val()!='')
{

$.post(serviceinfo+'checkuserdata', { datauser:$('#membercheck').val() }, function(data) { 
if(data.error.response)
{

$('.wrprPopPOS.wrprPopSaleCtm .wrnLS.wls10').html('<div class="errLS clErrBg"><span class="ico icoErr"></span></div><span class="spnErrLS clErrTxt fs02">Not Found</span>')
;
//alertbox(data.error.error);

//alertbox(data.error.error);


}
else
{
tempurserid=data['data']['userid'];
$('.wrprPopPOS.wrprPopSaleCtm .wrnLS.wls10').html('');

userlist[data['data']['userid']]=data['data'];
var strsetlocation='';
if(data['data']['disid']!='0'&&data['data']['tumid']!='0')
{

strsetlocation='<div class="ctmRoute clearfix"><span class="icoPOS icoCtmRoute icoCtmRoute10"></span><span class="lctRoute clTxtPOSB cutTxt fs03">'+data['data']['disname']+' - '+data['data']['tumname']+'</span></div>';


}
$('.wrprPopPOS.wrprPopSaleCtm img').attr('src',data['data']['simguser']['newpath']);
data['data']['simguser'];

var htmlstr=' <div class="ctmName"><span class="clTxtPOSB fs09 cutTxt">'+data['data']['displayname']+'</span></div><div class="ctmCred"><span class="clTxtPOSB fs03">'+data['data']['credit']+' Credit</span></div>'+strsetlocation;

$('.wrprPopPOS.wrprPopSaleCtm .wrpInCtmName').html(htmlstr);

}

});


}

}
function openpopupmember()
{
$('#membercheck').val('');
if(userid)
{
tempurserid=userid;
var data=userlist[userid];

var strsetlocation='';
if(data['disid']!='0'&&data['tumid']!='0')
{

strsetlocation='<div class="ctmRoute clearfix"><span class="icoPOS icoCtmRoute icoCtmRoute10"></span><span class="lctRoute clTxtPOSB cutTxt fs03">'+data['disname']+' - '+data['tumname']+'</span></div>';


}

$('.wrprPopPOS.wrprPopSaleCtm img').attr('src',data['simguser']['newpath']);


var htmlstr=' <div class="ctmName"><span class="clTxtPOSB fs09 cutTxt">'+data['displayname']+'</span></div><div class="ctmCred"><span class="clTxtPOSB fs03">'+data['credit']+' Credit</span></div>'+strsetlocation;

$('.wrprPopPOS.wrprPopSaleCtm .wrpInCtmName').html(htmlstr);




}else
{
$('.wrprPopPOS.wrprPopSaleCtm .wrpHdPopSaleCtm img').attr('src','/img/dfthmbuser.jpg');

var strtext='<div class="ctmName"><span class="clTxtPOSB fs09 cutTxt">Guest</span></div>';

$('.wrprPopPOS.wrprPopSaleCtm .wrpHdPopSaleCtm .wrpInCtmName').html(strtext);




}

$('.wrprPopPOS.wrprPopSaleCtm').fadeIn();


}
function savedatamembertemp()
{

if(tempurserid)
{
var data=userlist[tempurserid];
userid=tempurserid;
var strsetlocation='';
if(data['disid']!='0'&&data['tumid']!='0')
{

strsetlocation='<div class="ctmRoute clearfix"><span class="icoPOS icoCtmRoute icoCtmRoute10"></span><span class="lctRoute clTxtPOSB cutTxt fs03">'+data['disname']+' - '+data['tumname']+'</span></div>';


}

$('.wrprSaleCtm img').attr('src',data['simguser']['newpath']);

var strtext='<div class="ctmName"><span class="clTxtPOSB fs09 cutTxt">'+data['displayname']+'</span></div><div class="ctmCred"><span class="clTxtPOSB fs03">'+data['credit']+' Credit</span></div>'+strsetlocation;

$('.wrprSaleCtm .wrpInCtmName').html(strtext);

$('.wrprSaleCtm .wrpRgtCtm').hide();
$('.wrprPopPOS.wrprPopSaleCtm').fadeOut();





}else
{

userid=0;
$('.wrprSaleCtm img').attr('src','/img/dfthmbuser.jpg');

var strtext='<div class="ctmName"><span class="clTxtPOSB fs09 cutTxt">Guest</span></div>';

$('.wrprSaleCtm .wrpInCtmName').html(strtext);

$('.wrprSaleCtm .wrpRgtCtm').show();
$('.wrprPopPOS.wrprPopSaleCtm').fadeOut();

}

}
function savequestionrowdata()
{
var arraydata={};
arraydata['userid']=userid;
arraydata['guestname']=$('.wrprPopQst input[name="guestname"]').val();
if($('.wrprPopQst .ansq1.qstTg').length==0)
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Choose Gender');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}else
{

arraydata['gender']=$('.wrprPopQst .ansq1.qstTg').attr('title');

}


if($('.wrprPopQst .ansq2.qstTg').length==0)
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Choose Age');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}else
{

arraydata['age']=$('.wrprPopQst .ansq2.qstTg').attr('title');

$.post(serviceinfo+'savequestiondata', arraydata, function(data) { 

if(data.data)
{

readyanswer=data.data;
$('.wrprPopPOS.wrprPopQst').fadeOut();
saveorderalldata(2);
}

});


}






}
function saveorderalldata(status)
{
var arraydata={};
arraydata['status']=status;
if(status==2&&$('input.tenderInp').val()=='')
{

$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Input Cash');
$('.micPopPOS.micWrn').fadeIn("fast");
$('input.tenderInp').focus();
return false;
}

arraydata['sumall']=alldata;
arraydata['order']=orderid;
arraydata['userid']=userid;
arraydata['cash']=$('input.tenderInp').val();
arraydata['change']=$(".changeCost.clTxt3.fs11").html();
arraydata['suborder']=new Array();
var krow=0;

$.each( productlist, function( key, value ) {
//{count:1,title:title,img:img,productid:productid,price:price,discount:discount,suborderid:suborderid,credit:0,note:''}
arraydata['suborder'][krow]={
productid:value['productid'],
credit:value['credit'],
count:value['count'],
title:value['title'],
discount:value['discount'],
price:value['price'],
note:value['note']

};
krow++;

});


if(arraydata['suborder'].length==0)
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Choose Order');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}else
{
if(status==2)
{
if(userid)
{
$.post(serviceinfo+'checkquestiondata', {userid:userid}, function(data) { 

var answer1=1;
if(data.data)
{
readyanswer=data.data;
answer1=0;

}


if(answer1)
{

$('.wrprPopPOS.wrprPopQst').fadeIn();


}else
{
arraydata['questionid']=readyanswer;

$.post(serviceinfo+'saveorderall', arraydata, function(data) { 


$('.micPopPOS.micOrdCp').fadeIn();


setTimeout('$( ".micPopPOS.micOrdCp" ).fadeOut();',2000);



});


}



});


}else
{
if(readyanswer==0)
{
$('.wrprPopQst input[name="guestname"]').val('');
$('.wrprPopPOS.wrprPopQst').fadeIn();


}else
{

arraydata['guestname']=$('.wrprPopQst input[name="guestname"]').val();
arraydata['questionid']=readyanswer;

$.post(serviceinfo+'saveorderall', arraydata, function(data) { 

$('.micPopPOS.micOrdCp').fadeIn();
setTimeout('$( ".micPopPOS.micOrdCp" ).fadeOut();',2000);
cleardefaultall();

});



}



}





}else
{


var guestname=$('.wrprPopGuest input[name="guestname"]').val();


if(guestname!=''||userid!=0)
{
arraydata['guestname']=guestname;
$('.wrprPopGuest').fadeOut();
$('.wrprPopGuest input[name="guestname"]').val('');

$.post(serviceinfo+'saveorderall', arraydata, function(data) { 


$('.micPopPOS.micOrdCp').fadeIn();
setTimeout('$( ".micPopPOS.micOrdCp" ).fadeOut();',2000);
cleardefaultall();

});


}else
{

$('.wrprPopGuest').fadeIn();


}




}



}



}
function cleardefaultall()
{

var code = '<div class="noPOSData noLstPOS">\n<span class="icoPOS icoNoSaleLst"></span>\n<span class="fs05">No sales items.</span>\n<span class="fs02">Please select product or promotion.</span>\n</div>';
$('.wrpSaleLst').html(code);


var strtext='<div class="ctmName"><span class="clTxtPOSB fs09 cutTxt">Guest</span></div>';

$('.wrprSaleCtm .wrpInCtmName').html(strtext);

$('.wrprSaleCtm .wrpRgtCtm').show();
$('.spnSalePrc.clTxtPOSB.fs11').html('0'+' Baht');
$('input.tenderInp').val('');
$('.changeCost.clTxt3.fs11').html('0');


productlist={};
showdataprice=0;
orderid=0;
userid=0;
userlist={};
creditcount=1;
producttemp=0;
enablekeyborad=0;
opencalulator=0;
alldata=0;
alldata2=0;
tempurserid=0;
tempidcreditnow=0;
readyanswer=0;


}
function clearmemberdata()
{
tempurserid=0;

$('.wrprPopPOS.wrprPopSaleCtm .wrpHdPopSaleCtm img').attr('src','/img/dfthmbuser.jpg');

var strtext='<div class="ctmName"><span class="clTxtPOSB fs09 cutTxt">Guest</span></div>';

$('.wrprPopPOS.wrprPopSaleCtm .wrpHdPopSaleCtm .wrpInCtmName').html(strtext);







}
function changespecialstatus(status)
{
$('.wrprPopPOS.wrprPopSpc .btnPOSC.btnSpcType.fs05').removeClass('spcTg');
if(status==1)
{
$('.wrprPopPOS.wrprPopSpc .specialbtn').addClass('spcTg');
$('.wrprPopPOS.wrprPopSpc .numofcredit2').hide();
}else
{
$('.wrprPopPOS.wrprPopSpc .topupcreditbtn').addClass('spcTg');
$('.wrprPopPOS.wrprPopSpc .numofcredit2').show();
}



}

$(document).keydown(function(e){
      
     //console.log(e.which);
      /*
      8=== blackspace
      96 === 0
97 === 1
98 === 2
99 === 3
100 === 4
101 === 5
102 === 6
103 === 7
104 === 8
105 === 9

110 === .
107 === +
109 === -
106 === *
111 === */

    if(enablekeyborad)
    {
     if(e.which===8)
     {
     
     deletetexttoinput();
     e.preventDefault();
     
     }
     else if(e.which>95&&e.which<106)
     { 
     
     
     settexttoinput(''+(e.which-96));
     
     
     
     
     
     
     }
     else if(e.which===110)
     {
     
     settexttoinput('.');
     
     }
     else if(e.which===107)
     {
     
     settexttoinput('+');
     
     }
     else if(e.which===109)
     {
     
     settexttoinput('-');
     
     }
     else if(e.which===106)
     {
     
     settexttoinput('*');
     
     }
     else if(e.which===106)
     {
     
     settexttoinput('/');
     
     }
    else if(e.which===13)
    {
    calallchange();
    }
    
    
    }


      
      
    
    
    });

$("body").click(function(e) {

//console.log(e.target);

if(

   $(e.target).hasClass("wrprCalPOS")||
   $(e.target).hasClass("wrpCalPOS")||
   $(e.target).hasClass("spnCal")||
   $(e.target).hasClass("icoPOS")||
   $(e.target).hasClass("calPlus")||
   $(e.target).hasClass("calMinus")||
   $(e.target).hasClass("calErase")||
   $(e.target).hasClass("wrpOutMicPopPOS")||
   $(e.target).hasClass("clTxtPOSW")||
   $(e.target).hasClass("btnPOSW")||
   $(e.target).hasClass("tenderInp")||
   $(e.target).hasClass("closeCal")||
   $(e.target).hasClass("calAcp")||
   $(e.target).hasClass("cal00")||
   $(e.target).hasClass("cal0")||
   $(e.target).hasClass("calPoint")||
   $(e.target).hasClass("cal3")||
   $(e.target).hasClass("cal2")||
   $(e.target).hasClass("cal1")||
   $(e.target).hasClass("cal6")||
   $(e.target).hasClass("cal5")||
   $(e.target).hasClass("cal4")||
   $(e.target).hasClass("cal9")||
   $(e.target).hasClass("cal8")||
   $(e.target).hasClass("inpSpcPrc")||
   $(e.target).hasClass("cal7")
   
   
   
   
   
   )
  {
  
  
  }else
  {
  closecalcutator();
  
  }


});
var laststringinput="input.tenderInp";
$("input.tenderInp").focus(function(e) {
laststringinput="input.tenderInp";
opencalcutator();


});

$("input.NumOfCredit").focus(function(e) {
laststringinput="input.NumOfCredit";
opencalcutator();
$('.wrpOutPopSpc').addClass('l170p');

});


$("input.PriceOfCredit").focus(function(e) {
laststringinput="input.PriceOfCredit";
opencalcutator();
$('.wrpOutPopSpc').addClass('l170p');

});

function tagsearchdata(tagid)
{
$('.tagalldataset').hide();
$('.tagdataset-'+tagid).fadeIn();


}

$('#textsearchproductstring').keyup(function(e) {
    var enterKey = 13;
    if (e.which == enterKey){
        textsearchalldata();
     }
 });
function textsearchalldata()
{
if($('#textsearchproductstring').hasClass('inpPdSrchExp'))
{
$('.tagalldataset').hide();

if($('#textsearchproductstring').val())
{
var resultdata=searchjsonobject(jsonproductstring, $('#textsearchproductstring').val()) ;
if(resultdata.length)
{
$.each( resultdata, function( resultkey, resultvalue ) {

$('.productisdata-'+resultvalue.productid).show();


});

}

}else
{

$('.tagalldataset').fadeIn();
}

}


}
var codepromotion;
function submitcodepromotion()
{

calculateorder(codepromotion.productid,codepromotion.simg.newpath,codepromotion.title,0,codepromotion.price,0)


}

function checkcodepromotion()
{
if($('.inpCodePmt').val())
{
$.post(serviceinfo+'checkcodethepromotion', {code:$('.inpCodePmt').val()}, function(data) { 


if(data.error.response)
{
$('.mnPopCpEp .fs11').html(data.error.error[0].msg);

$('.mnPopCpEp').fadeIn();


}else
{
codepromotion=data.data;
$('.mnPopCpAv span.fs09').html(data.data.title);
$('.mnPopCpAv').fadeIn();

}

});

}



}

var jsonproductstring=<?=json_encode($data['product'])?>;

function searchjsonobject(source, name) {
    var results;

    name = name.toUpperCase();
    results = source.filter(function(entry) {

        return entry.title.toUpperCase().indexOf(name) !== -1;
    });
    return results;
}


function opencreditpopup()
{
tempidcreditnow=0;
$('input[name="namecredit"]').val('');
$('input[name="numcredit"]').val('');
$('input[name="pricecredit"]').val('');
$('textarea[name="notecredit"]').val('');
$('.wrprPopPOS.wrprPopSpc').fadeIn();

$('.wrprPopSpc .wrpInBtnBdSaleLst').hide();

}

<?if($data['orderlist']){?>


orderid=<?=$data['orderlist']['orderid']?>;
userid=<?=$data['orderlist']['userid']?>;
alldata=<?=$data['orderlist']['sumall']?>;

<? if($data['orderlist']['userid']){?>
tempurserid=<?=$data['orderlist']['userid']?>;
userlist[<?=$data['orderlist']['userid']?>]=<?=json_encode($data['orderlist']['user'])?>;


savedatamembertemp()

<?}?>
<? if(count($data['orderlist']['suborder'])){

foreach($data['orderlist']['suborder'] as $suborder)
{

if($suborder['productlist']['title'])
{

$title=$suborder['productlist']['title'];
$img=$suborder['productlist']['simg']['newpath'];

}else
{
$title=$suborder['title'];
$img='';

}

if($suborder['price']!='0.00')
{

if(strpos($suborder['price'],'.00')!==false)
{
$suborder['price']=intval($suborder['price']);

}
$price=$suborder['price'];
$discount=0;


}else
{
$price=0;

if(strpos($suborder['discount'],'.00')!==false)
{
$suborder['discount']=intval($suborder['discount']);

}


$discount=$suborder['discount'] ;


}

?>
<? for($i=0;$i<$suborder['count'];$i++){?>
calculateorder(<?=$suborder['productid']?>,'<?=$img?>','<?=$title?>',<?=$price?>,<?=$discount?>,<?=$suborder['suborderid']?>,'<?=$suborder['note']?>')
<?}?>

<?
}
}?>


<?

if($data['orderlist']['cash']!='0.00')
{
if(strpos($data['orderlist']['cash'],'.00')!==false)
{
$data['orderlist']['cash']=intval($data['orderlist']['cash']);

}

if(strpos($data['orderlist']['change'],'.00')!==false)
{
$data['orderlist']['change']=intval($data['orderlist']['change']);

}

?>
$('input.tenderInp').val('<?=$data['orderlist']['cash']?>');




$('.change .changeCost').html('<?=$data['orderlist']['change']?>');
<?


}


}?>


$( document ).ready(function() {


$('#rowuserupload').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':1,
         'crop':true,
         'width':300,
         'height':300,
         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
        $('.wrpUsrImgRgt img').attr('src',filelink);
         $('.wrpUsrImgRgt input[name="simgmid[]"]').val(setting['imgmid']);
         $('.wrpUsrImgRgt input[name="imgmid[]"]').val(setting['imgmid']);
        
         //alert(filename);
         }
   });
      
$( "#re-birthday" ).datepicker();        


  var rownow=1;
  var rowchecknow=0;
  var handler = function() {
     
    if(rowchecknow==0)
    {
    rowchecknow=1;
     $('#feature'+rownow+' .mapdata').gmap3({
          getgeoloc:{
            callback : function(latLng){
            
              if (latLng){
              
              $('#feature'+rownow+' input[name="lat[]"]').val(latLng.lat());
              $('#feature'+rownow+' input[name="lng[]"]').val(latLng.lng()); 
              
               // $('#test1-result').html('localised !');
                $(this).gmap3({
                  marker:{ 
                    latLng:latLng,
                    options:{
                        draggable: true
                    },
                    events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('#feature'+rownow+' input[name="lat[]"]').val(marker.position.lat());
                        $('#feature'+rownow+' input[name="lng[]"]').val(marker.position.lng()); 
                        
                        
                        }
                        } 
                    
                    
                  },
                      map:{
                        options:{
                          zoom: 15,
                          center :latLng
                        }
                      }
                });
                
                
                $(this).unbind('click');
              } 
              else {

              }
            }
          }
        });
    }
        
      
     
     
     };
     
     $('#feature'+rownow+' .mapdata').bind('click', handler);
   
   
     $('#feature'+rownow+' input[name="detail[]"]').keyup(function() {
    
              if(rowchecknow==0)
              {
              rowchecknow=1;
              }
             // console.log(1);
              
             $('#feature'+rownow+' .mapdata').gmap3({
             
             
              getlatlng:{
                address:  $(this).val(),
                callback: function(results){
                
                  
                  
                  if ( !results ) return;
                  
                  
                  $(this).gmap3({
                    clear: {
                      name:["marker"],
                      last: true
                    }
                  });
                 
//console.log(results[0].geometry);
                 $('#feature'+rownow+' input[name="lat[]"]').val(results[0].geometry.location.lat());
                 $('#feature'+rownow+' input[name="lng[]"]').val(results[0].geometry.location.lng()); 
                  
                  $(this).gmap3({
                    marker:{
                      latLng:results[0].geometry.location,
                      options:{
                        draggable: true
                        },
                      events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('#feature'+rownow+' input[name="lat[]"]').val(marker.position.lat());
                        $('#feature'+rownow+' input[name="lng[]"]').val(marker.position.lng()); 
                        
                        
                        }
                        }   
                        
                        
                    },
                      map:{
                        options:{
                          zoom: 15,
                          center :results[0].geometry.location
                        }
                      }
                  });
                  
                  
                  
                }
              }
              
              
              
              });  
              
     
     });
     


});


</script>
